<?php session_start();
//validaAcesso(); nao pode ter valida
if($_GET["cont"]){
     echo'<link rel="stylesheet" type="text/css" href="../css2/css.css" media="screen" title="COLABORE Hotelaria">';
     include"../admin/conexao.jsp";
     $legendas="<hr>
            <div id='topbar' style='position:absolute; top:23px; left:80%; visibility: hidden; z-index: 100;'>
               	 <a href='javascript:window.history.go(-1)'><img src='../images/btn_voltar2.gif' width='110' height='29' border='0'></a><BR>
				 <a href='javascript:window.close()'><img src='../images/btn_fechar2.gif' width='110' height='29' border='0'></a>
			   </div>
               ";
?>     
<script type="text/javascript">


var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 340 //set x offset of bar in pixels
var startY = 100 //set y offset of bar in pixels
var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("topbar").style.visibility="hidden"
}

function staticbar(){
	barheight=document.getElementById("topbar").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("topbar");
	stayTopLeft();
}

if (window.addEventListener)
window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
window.attachEvent("onload", staticbar)
else if (document.getElementById)
window.onload=staticbar
</script>

<?php       
}
if($_GET['operacao'] == 'c'){
    echo"<h2>Cancelar Reserva:</h2>";
}elseif($_GET['operacao'] == 'a'){
    echo"<h2>Alterar Observa&ccedil;&atilde;o:</h2>";
}

retorna_midia($_GET[cod_midia]);


if($_GET["cont"]==1){
     $sql="select obs_reserva from bibl_reservadas where cod_reserva={$_GET['cod_reserva']}";
     $linha=$_SESSION['ADOCnn']->Execute("$sql");

     echo"<form method='POST' action='?cont=2&pid={$_GET['pid']}' autocomplete='off'>

     Motivo / Observa&ccedil;&atilde;o:<BR>
     <textarea  multiple rows='5' cols='50' maxlength='220' name='pobs'>{$linha->fields[0]}</textarea><BR><BR>
     <input type='hidden' name='pcod_reserva' value='{$_GET['cod_reserva']}'>
     ";
     if($_GET['operacao'] == 'c'){
         echo "<input type='submit' name='cancelar' value='Cancelar a Reserva'>";
     }elseif($_GET['operacao'] == 'a'){
         echo "<input type='submit' name='alterar' value='Alterar Observa&ccedil;&atilde;o'>";
     }
     echo"</form>";
     
}elseif($_GET["cont"]==2){

     if($_POST['cancelar']){
          $hoje=date("Y-m-d");
          $sql="update bibl_reservadas set obs_reserva='{$_POST['pobs']}', cancelada=1, ref_quem_baixa={$_SESSION[loginCK_]}, data_baixa='$hoje' where cod_reserva = {$_POST['pcod_reserva']}";
     }
     if($_POST['alterar']){
          $sql="update bibl_reservadas set obs_reserva='{$_POST['pobs']}' where cod_reserva = {$_POST['pcod_reserva']}";
     }


     if(!$linha=$_SESSION['ADOCnn']->Execute("$sql")){
         echo"Erro ao baixar [cont2]<BR>";
         echo $sql;
     }else{
         echo"<u>Opera&ccedil;&atilde;o:</u> <b>{$_POST['cancelar']} {$_POST['alterar']}</b>, realizada com Sucesso !!!<BR>";
         echo"<body onLoad=\"javascript:window.opener.location='../index.jsp?emprest=2&cont=4&pid={$_GET['pid']}';window.self.close();\">";
     }


}



echo $legendas;
?>
